import * as api from '@/views/case_module/api'
export const crudOptions = (vm) => {
  return {
    rowHandle: {
      view: {
        disabled () {
          // return false
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        disabled () {
          // return false
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        disabled () {
          // return false
          return !vm.hasPermissions('Delete')
        }
      },
      fixed: 'right'
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false
    },
    formOptions: { // 表单宽度
      type: 'drawer',
      draggable: false, // 关闭拖拽
      fullscreen: false, // 关闭全屏功能
      size: '50%'
    },
    indexRow: { // 序号
      title: '序号',
      align: 'center',
      width: 60
    },
    selectionRow: { // 多选框
      align: 'center',
      width: 46
    },
    columns: [
      {
        title: 'Id',
        key: 'id',
        form: { // 表单配置
          disabled: true // 禁用表单编辑
        },
        view: { disabled: true },
        disabled: true, // 隐藏列
        sortable: true
      },
      {
        title: '缺陷描述',
        key: 'defect_des',
        width: 750,
        showOverflow: true,
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '缺陷描述' }],
          component: {
            span: 24,
            props: {
              clearable: true
            },
            placeholder: '请输入缺陷描述'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '缺陷优先级',
        width: 120,
        key: 'defect_priority',
        type: 'select',
        dict: {
          data: vm.dictionary('defect_priority')
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '缺陷优先级' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择缺陷优先级'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '缺陷等级',
        width: 120,
        key: 'defect_level',
        type: 'select',
        dict: {
          data: vm.dictionary('defect_level')
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '缺陷等级' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择缺陷等级'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '缺陷状态',
        width: 120,
        key: 'defect_status',
        type: 'select',
        dict: {
          data: vm.dictionary('defect_status')
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '缺陷状态' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择缺陷状态'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '缺陷类型',
        key: 'defect_type',
        type: 'select',
        width: 150,
        dict: {
          data: vm.dictionary('defect_type')
        }, // 数据字典
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '缺陷类型' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择缺陷类型'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '所属项目',
        key: 'project_belong',
        type: 'select',
        width: 100,
        dict: {
          cache: false,
          url: '/quality/project/',
          value: 'id',
          label: 'project_name'
        }, // 数据字典
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: true, // 禁用表单编辑
          component: {
            props: {
              clearable: true
            },
            placeholder: '请选择所属项目'
          },
          itemProps: {
            class: { yxtInput: true }
          },
          valueChange (key, value, form, { getColumn, mode, component, immediate, getComponent }) {
            form.module_belong = undefined // 将“module_belong”的值置空
            if (value) {
              getComponent('module_belong').reloadDict() // 执行city的select组件的reloadDict()方法，触发“city”重新加载字典
            }
          }
        },
        sortable: false
      },
      {
        title: '所属模块',
        key: 'module_belong',
        type: 'tree-selector',
        width: 150,
        dict: {
          isTree: true,
          label: 'module_name',
          value: 'id',
          cache: false,
          getData: (url, dict, { form, component }) => { // 配置此参数会覆盖全局的getRemoteDictFunc
            return api.ModuleLazy().then(ret => { return ret })
          }
        },
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '用例模块' }],
          component: {
            props: {
              multiple: false, clearable: true
            },
            placeholder: '请选择用例模块'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '影响范围',
        key: 'effect_range',
        disabled: true, // 隐藏列
        form: { // 表单配置
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入影响范围'
          }
        },
        sortable: false
      },
      {
        title: '测试人员',
        width: 100,
        key: 'tester',
        search: { disabled: false }, // 开启查询
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '测试人员' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入测试人员'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '开发人员',
        width: 100,
        key: 'developer',
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '开发人员' }],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入开发人员'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: false
      },
      {
        title: '缺陷产生时间',
        key: 'accident_time',
        disabled: true,
        search: {
          disabled: false,
          width: 360,
          component: { // 查询框组件配置，默认根据form配置生成
            name: 'el-date-picker',
            props: {
              type: 'daterange',
              'range-separator': '至',
              'start-placeholder': '开始',
              'end-placeholder': '结束',
              valueFormat: 'yyyy-MM-dd'
            }
          }
        },
        form: { // 表单配置
          component: {
            placeholder: '请选择缺陷产生时间',
            props: {
              valueFormat: 'yyyy-MM-dd'
            }
          },
          disabled: false // 禁用表单编辑
        },
        // 提交时,处理数据
        valueResolve (row, col) {
          if (row[col.key] instanceof Array) {
            row[col.key] = row[col.key].join(',')
          }
        },
        type: 'date'
      },
      {
        title: '缺陷解决时间',
        key: 'resolution_time',
        type: 'date',
        form: { // 表单配置
          component: {
            placeholder: '请选择缺陷解决时间',
            props: {
              valueFormat: 'yyyy-MM-dd'
            }
          },
          disabled: false // 禁用表单编辑
        },
        disabled: true, // 隐藏列
        sortable: true
      },
      {
        title: '重现步骤',
        key: 'reproduce_step',
        type: 'editor-quill',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          rules: [{ required: true, message: '重现步骤' }],
          value: '【重现步骤】\n\n【实际结果】\n\n【期望结果】',
          component: {
            span: 24,
            props: {
              clearable: true
            },
            placeholder: '请输入重现步骤'
          },
          itemProps: {
            class: { yxtInput: true }
          }
        },
        sortable: true
      },
      {
        title: '产生原因',
        key: 'cause_occurrence',
        type: 'textarea',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            showWordLimit: true,
            maxlength: '200',
            props: {
              clearable: true,
              type: 'textarea'
            },
            placeholder: '请输入产生原因'
          }
        },
        sortable: false
      },
      {
        title: '预防措施',
        key: 'improvement_action',
        type: 'textarea',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: false, // 禁用表单编辑
          component: {
            showWordLimit: true,
            maxlength: '200',
            props: {
              clearable: true,
              type: 'textarea'
            },
            placeholder: '请输入预防措施'
          }
        },
        sortable: true
      },
      {
        title: '创建人',
        key: 'creator_name',
        disabled: true, // 隐藏列
        form: { // 表单配置
          disabled: true // 禁用表单编辑
        },
        sortable: false
      }
    ].concat(vm.commonEndColumns({
      update_datetime: { showTable: false },
      modifier_name: { showTable: true }
    }))
  }
}
